﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;

public partial class Common_ChoiceFolderFiles_List : System.Web.UI.Page
{
    public string sHtml = "<tr>";
    protected string sType = "1";     //1是查询，2是左边树传值


    protected string sFilesName = "";  //文件名
    protected string sFolderID = "";     //文件夹ID
    protected string sFolderName = "";  //文件夹名称

    BaiMaSoft.Conn.DataConn MyDataConn = new BaiMaSoft.Conn.DataConn();
    public SqlConnection myconn;
    public SqlCommand mycomm;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            try
            {
                sFilesName = Request.QueryString["FilesName"].ToString().Trim();
            }
            catch
            {
                sFilesName = "";
            }

            try
            {
                sFolderID = Request.QueryString["FolderID"].ToString().Trim();
            }
            catch
            {
                sFolderID = "0"; ;
            }

            try
            {
                sFolderName = Request.QueryString["FolderName"].ToString().Trim();
            }
            catch
            {
                sFolderName = "";
            }

            if (sFilesName.Trim() != "" || sFolderID.Trim() != "")
            {
                if (sFolderID.Trim() != "" && sFolderName.Trim() != "")
                {
                    OrgCount.Value = "1";
                    OrgName.Text = "&nbsp;&nbsp; <input type='checkbox' id='OrgCK' name='OrgCK'  onclick='ChoiceOrg(this);'  value='" + sFolderID.Trim() + "," + sFolderName.Trim() + "' >" + sFolderName.Trim() + "&nbsp;&nbsp;<input type='checkbox' id='AllPerCK' name='AllPerCK'  onclick='ChoiceAllPer(this);' >全选 ";
                }
                else
                {
                    OrgCount.Value = "0";
                    OrgName.Text = "&nbsp;&nbsp; <input type='checkbox' id='AllPerCK' name='AllPerCK'  onclick='ChoiceAllPer(this);' >全选 ";  // 
                }

                IniInfo(sFilesName, sFolderID);
            }
        }
    }

    public void IniInfo(string sFilesName, string sFolderID)
    {
        MyDataConn.Connection.Open();
        string proc = @" SELECT a.ID, a.FolderID, a.Name, g.Name AS FolderName
                         FROM DataFile a LEFT OUTER JOIN
                              DataFolder g ON a.FolderID = g.ID where (1=1) ";
        if (sFilesName.Trim() != "")
        {
            proc += " and a.Name  like '%" + sFilesName.Trim() + "%' ";
        }

        if (sFolderID.Trim() != "")
        {
            proc += " and a.FolderID  = '" + sFolderID.Trim() + "' ";
        }

        proc += "  ORDER BY a.DOrder, a.CreatDT ";
        mycomm = new SqlCommand(proc, MyDataConn.Connection);
        SqlDataReader ShowReader = mycomm.ExecuteReader();
        int iPersCount = 0; //人员数


        while (ShowReader.Read())
        {
            string FolderID = ShowReader["FolderID"].ToString().Trim();      // 文件夹ID

            string FileName = ShowReader["Name"].ToString().Trim();   // 文件名称
            string FileID = ShowReader["ID"].ToString().Trim();     // 文件ID

            string ChioceBox = "<TD> <input type=\"checkbox\" name=\"PersCK\" id=\"PersCK\"  onclick=\"ChoicePer(this);\" value=\"" + FileID + "," + FileName + "\" />" + FileName + "</td>";

            if (iPersCount % 2 == 0)   //一行显示3个员工姓名
            {
                sHtml += " </tr><tr> " + ChioceBox;
            }
            else
            {
                sHtml += ChioceBox;
            }
            iPersCount += 1;
        }
        PersCount.Value = Convert.ToString(iPersCount);
        ShowReader.Close();
        MyDataConn.Connection.Close();
        sHtml += "</tr>";
    }
}
